export function chunkArray(arr: any[] = [], chunkSize = 200) {
  const result: any[] = [];
  const len = arr.length;

  // 循环分块
  for (let i = 0; i < len; i += chunkSize) {
    result.push(arr.slice(i, i + chunkSize));
  }

  return result;
}

export function sendMessage<T>(message: any): Promise<T> {
  return new Promise((resolve) => {
    chrome.runtime.sendMessage(message, resolve);
  });
}

// 检查token是否过期（针对时间戳格式）
export function checkTokenExpired(expiresIn: string | number): boolean {
  if (!expiresIn) return true;

  // 统一转换为数字
  const expiryTime =
    typeof expiresIn === "string" ? parseInt(expiresIn) : expiresIn;

  // 获取当前时间戳（毫秒）
  const currentTime = new Date().getTime();
  return currentTime > expiryTime;
}

export function sleep(delay = 2000) {
  return new Promise((resolve) => {
    setTimeout(()=>{
      resolve(true)
    }, delay)
  })
}